import {
  SETALLREAD,
  DELMSG,
  SETMSGSTATE
} from './actionTypes'

const defaultState = {
  msgList : [
    {
      id:1,
      title: '饱谙世事懒开口',
      hasRead: false,
      desc: '只是一个描述',
      avatar: 'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3999162594,1780997618&fm=11&gp=0.jpg'
    },
    {
      id:2,
      title: '看破人情频点头',
      hasRead: false,
      desc: '只是一个描述',
      avatar: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602579101825&di=6e59b444bd55658c09258ff9e8b15b7c&imgtype=0&src=http%3A%2F%2Fdiy.qqjay.com%2Fu2%2F2014%2F0408%2F756dd9c10a90b04ed51d704c69cdb052.jpg'
    },
    {
      id: 3,
      title: '几人悟透此中妙',
      hasRead: false,
      desc: '只是一个描述',
      avatar: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602579139871&di=8021d839384ab904daa2ef6429054cfe&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimages%2F20190129%2F8478c326fa174158859b9ac093e36938.jpeg'
    },
    {
      id: 4,
      title: '无心惹来万千愁',
      hasRead: false,
      desc: '只是一个描述',
      avatar: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602579139869&di=035c4f9158e771be8a2af1a958f7da62&imgtype=0&src=http%3A%2F%2Fattach.bbs.miui.com%2Fforum%2F201108%2F12%2F153524babrex391xoaz5za.jpg'
    },
  ]
}



const reducer = (state = defaultState,action) => {
  let newState = JSON.parse(JSON.stringify(state))
  switch (action.type) {
    case SETALLREAD:
      newState.msgList.forEach(msg=> msg.hasRead = true)
      break;
    case DELMSG:
      newState.msgList.splice(action.index,1)
      break;
    case SETMSGSTATE: 
      newState.msgList[action.index].hasRead = true
      break
    default: break;  
  }

  return newState
}

export default reducer